﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;

public partial class quenmatkhau : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataConnection.str = @"Data Source=xe;User ID=ODER;Password=12345";
    }

    protected void bthuy_Click(object sender, EventArgs e)
    {
        Response.Redirect("trangchu.aspx");
    }

    protected void btnlaymatkhau_Click(object sender, EventArgs e)
    {
        string tendn = txttendn.Text;
        string email = txtemail.Text;
        //string cmd = "select * from Users where TenDN=@tendn and Email=@email";
        OracleParameter[] thamso = new OracleParameter[]
        {
            new OracleParameter("p_tendn",tendn),
            new OracleParameter("p_email",email),
        };
        DataTable dt = DataConnection.GetDatatableByStoreProcedureNameCursor("NGOCTRAN.sp_getUserByTenDNEmail", thamso);
        if (dt.Rows.Count > 0)
        {
            string passwordmoi = taongaunhien().ToString();
            OracleParameter[] thamso1 = new OracleParameter[]
            {
                new OracleParameter("p_matkhaudn",passwordmoi),
                new OracleParameter("p_tendn",tendn),
            };
            DataConnection.TruyVan_ThamSo("NGOCTRAN.UPDATE_PASS", thamso1);
            string diachigui = email;
            string tieude = "Lấy lại mật khẩu mới";
            string noidung = "Password mới của bạn là: " + passwordmoi;
            DataConnection.SendMail_By_Gmail(diachigui, tieude, noidung);
            Response.Redirect("thongbao.aspx?ID=2");
        }
        else
        {
            lbloi.Text = "Tên Đăng nhập hoặc Email của bạn không chính xác";
        }

    }
    int taongaunhien()
    {
        int min = 1111;
        int max = 9999;
        Random random = new Random();
        return random.Next(min, max);
    }
}